﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FILSTARTUPS_MOBILE.Models;

namespace FILSTARTUPS_MOBILE.Helpers
{
    public class ModeratorAccessAttribute : AuthorizeAttribute
    {
        FilStatUpsEntities mobile_connect = new FilStatUpsEntities();
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null) throw new ArgumentNullException("httpContext");
            // Make sure the user is authenticated.
            if (httpContext.User.Identity.IsAuthenticated == false) return false;

            var user_role = mobile_connect.Members.Where(m => m.roleidFK.Equals(1) && m.emailaddress.Equals(httpContext.User.Identity.Name)).SingleOrDefault();

            if (user_role != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}